package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnBean {
    private String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    private String url = "jdbc:sqlserver://";
    private String database = "localhost:1433;databasename=Company_Travel;encrypt=true;trustServerCertificate=true";
    private String userName = "sa";
    private String password = "123";
    private Connection connection = null;

    public ConnBean() {
    }

    public Connection getConnection() {
        try {
            Class.forName(this.driver);
        } catch (ClassNotFoundException var4) {
            var4.printStackTrace();
        }

        String urll = this.url + this.database;
        System.out.println(urll);

        try {
            this.connection = DriverManager.getConnection(this.url + this.database, this.userName, this.password);
        } catch (SQLException var3) {
            var3.printStackTrace();
        }

        if (this.connection != null) {
            System.out.println("connection is correct");
            return this.connection;
        } else {
            System.out.println("connection is not correct");
            return null;
        }
    }

    public void closeConnection() {
        try {
            if (this.connection != null) {
                this.connection.close();
            }

            this.connection = null;
        } catch (SQLException var2) {
            var2.printStackTrace();
        }

    }

    public String getDriver() {
        return this.driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public String getUrl() {
        return this.url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getDatabase() {
        return this.database;
    }

    public void setDatabase(String database) {
        this.database = database;
    }

    public String getUserName() {
        return this.userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
